package alertPeople

import (
	"context"
	"devops-super/api/alerts/v1"
	"devops-super/internal/model/entity"
	"devops-super/internal/service"
	"github.com/gogf/gf/v2/os/gtime"
)

// GetPageLst 分页获取告警人员列表
func (*ControllerV1) GetPageLst(ctx context.Context, req *v1.AlertPeopleGetPageLstReq) (res *v1.AlertPeopleGetPageLstRes, err error) {
	res = &v1.AlertPeopleGetPageLstRes{}
	res.PageLstRes, err = service.AlertPeople().GetPageLst(ctx, req)
	return
}

// Add 新增告警人员
func (*ControllerV1) Add(ctx context.Context, req *v1.AlertPeopleAddReq) (res *v1.AlertPeopleAddRes, err error) {
	alertPeople := &entity.AlertPeople{
		Name:             req.Name,
		DeptId:           req.DeptId,
		Phone:            req.Phone,
		Email:            req.Email,
		Wechat:           req.Wechat,
		Language:         req.Language,
		Remark:           req.Remark,
		ReceiveFrequency: req.ReceiveFrequency,
		CreatedAt:        gtime.Now(),
	}
	err = service.AlertPeople().Add(ctx, alertPeople)
	return
}

// Upt 更新告警人员
func (*ControllerV1) Upt(ctx context.Context, req *v1.AlertPeopleUptReq) (res *v1.AlertPeopleUptRes, err error) {
	alertPeople := &entity.AlertPeople{
		Id:               uint64(req.Id),
		Name:             req.Name,
		DeptId:           req.DeptId,
		Phone:            req.Phone,
		Email:            req.Email,
		Wechat:           req.Wechat,
		Language:         req.Language,
		Remark:           req.Remark,
		ReceiveFrequency: req.ReceiveFrequency,
		UpdatedAt:        gtime.Now(),
	}
	err = service.AlertPeople().Upt(ctx, alertPeople)
	return
}

// UptStatus 更新告警人员状态
func (*ControllerV1) UptStatus(ctx context.Context, req *v1.AlertPeopleUptStatusReq) (res *v1.AlertPeopleUptStatusRes, err error) {
	err = service.AlertPeople().UptStatus(ctx, req.Id, req.Status)
	return
}

// Del 删除告警人员
func (*ControllerV1) Del(ctx context.Context, req *v1.AlertPeopleDelReq) (res *v1.AlertPeopleDelRes, err error) {
	err = service.AlertPeople().Del(ctx, req.Id)
	return
}

// GetOne 获取一条告警人员信息
func (*ControllerV1) GetOne(ctx context.Context, req *v1.AlertPeopleGetOneReq) (res *v1.AlertPeopleGetOneRes, err error) {
	res1, err := service.AlertPeople().GetOne(ctx, req.Id)
	if err != nil {
		return
	}
	res = new(v1.AlertPeopleGetOneRes)
	res.Info = res1
	return
}

// GetOptions 获取告警人员选项
func (*ControllerV1) GetOptions(ctx context.Context, req *v1.AlertPeopleGetOptionsReq) (res *v1.AlertPeopleGetOptionsRes, err error) {
	res, err = service.AlertPeople().GetOptions(ctx, req)
	return
}